﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HiLand.Utility.Finance;

namespace DotNET4Study.Loan
{
    class HilandLoanStudy
    {
        public static void Execute()
        {
            //CPMLoan.GetPaymentSchedule();
            ValidRate();
        }

        private static void ValidRate()
        {
            ValidAnnualRate(0.48);
            ValidMonthlyRate(0.04);
            ValidPaymentSchedule();
        }

        private static void ValidAnnualRate(double annualRate)
        {
            RateConverter rateConverter = new SimpleRateConverter(annualRate, PaymentTermTypes.Annual);
            Console.WriteLine("以下验证年利率的转换");
            Console.WriteLine("其对应的年利率为{0}向其他类型的转换", annualRate);
            Console.WriteLine("其对应的日利率为{0}", rateConverter.DailyRate);
            Console.WriteLine("其对应的月利率为{0}", rateConverter.MonthlyRate);
        }

        private static void ValidMonthlyRate(double monthlyRate)
        {
            RateConverter rateConverter = new SimpleRateConverter(monthlyRate, PaymentTermTypes.Monthly);
            Console.WriteLine("以下验证月利率的转换");
            Console.WriteLine("一下验证年利率{0}向其他类型的转换", rateConverter.AnnualRate);
            Console.WriteLine("其对应的日利率为{0}", rateConverter.DailyRate);
            Console.WriteLine("其对应的月利率为{0}", rateConverter.MonthlyRate);
        }

        private static void ValidPaymentSchedule()
        {
            Console.WriteLine("以下代码验证还款日程");
            List<Payment> list = CPMLoan.GetPaymentSchedule(0.04, 12, 5000, PaymentTermTypes.Monthly, new DateTime(2011, 8, 18));
            for(int i=0;i<list.Count;i++)
            {
                Payment payment= list[i];
                Console.WriteLine("{0}({5}) {1}||{2}||{3}||{4}",payment.Number,payment.Amount,payment.Principal,payment.Interest,payment.PrincipalBalance,payment.PaymentDate.ToShortDateString());
            }
        }
    }
}
